/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Br.Com.Cds.Academia.View;

import Br.Com.Cds.Academia.Conta.ContaBean;
import Br.Com.Cds.Academia.Conta.ContaControl;
import java.awt.Dimension;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author p
 */
public class TelaCadastroConta extends javax.swing.JFrame {
    
    DefaultTableModel tmContas = new DefaultTableModel(null,new String[]{"Conta","Tipo"}); 
    ListSelectionModel lsmContas; 
    String tipoCadastro; 
    List <ContaBean> contas;
    
        private void listarContas(){ 

        ContaControl gru = new ContaControl();
        contas = gru.listarConta("%" + TFpesquisarconta.getText().trim() + "%");
        mostrarContas(contas);

    }
        
        private void mostrarContas(List<ContaBean> contas){ 
        if ( contas.size()==0){                        
            tmContas.setRowCount(0);
            JOptionPane.showMessageDialog(this,"Registro Não Encontrado!","CDS ACADEMIA",JOptionPane.INFORMATION_MESSAGE);
        }else{                                       
            while(tmContas.getRowCount() > 0){
                  tmContas.removeRow(0);

            }
            String[] campos = new String[] { null,null}; 
            for (int i = 0;i < contas.size(); i++){   
                tmContas.addRow(campos);               
                tmContas.setValueAt(contas.get(i).getConta(),i,0);
                tmContas.setValueAt(contas.get(i).getTipo(),i,1);
  
            }
        }

    }
        
        private void tbContasLinhaSelecionada(JTable tb){     

        if(tb.getSelectedRow() != -1){                      
            TFdescricaoconta.setText(contas.get(tb.getSelectedRow()).getConta());
            String pegaTipo = contas.get(tb.getSelectedRow()).getTipo();
            JCBtipoconta.setSelectedItem(pegaTipo);
            String pegaStatus = contas.get(tb.getSelectedRow()).getStatus(); 
            if(pegaStatus.equals("ATIVO")){                
               JRBativoconta.setSelected(true);
               JRBinativoconta.setSelected(false);
            }else if(pegaStatus.equals("INATIVO")){
               JRBinativoconta.setSelected(true);
               JRBativoconta.setSelected(false);
            }

            BTalterarcadastro.setEnabled(true);    
            BTnovocadastro.setEnabled(true);       
            BTsalvarcadastro.setEnabled(false);


       }else{ // Se não houver nenhuma linha selecionada, deixa os campos em branco.
          
            TFdescricaoconta.setText("");
            JCBtipoconta.setEnabled(false);
            JRBativoconta.setSelected(false);
            JRBinativoconta.setSelected(false);
            BTalterarcadastro.setEnabled(false);

       }

    }
        
        public void limpaTabela(){  
    DefaultTableModel tblRemove = (DefaultTableModel)TBtabelaconta.getModel();  
      
    if (tblRemove.getRowCount() > 0){  
        for (int i=1;i<=tblRemove.getRowCount();i++){  
            tblRemove.removeRow(0);  
        }              
    }  
  
}  
          
         private JTable getJTable() {        //Metódo para definir o tamanho das colunas na JTable.
     if (TBtabelaconta == null) {
         TBtabelaconta = new JTable(tmContas);
         defineRenderers();
   }       return TBtabelaconta;
   
 }
         
         private void defineRenderers() {
     DefaultTableCellRenderer rendererCentro = new DefaultTableCellRenderer();
     rendererCentro.setHorizontalAlignment(SwingConstants.CENTER);
     DefaultTableCellRenderer rendererDireita = new DefaultTableCellRenderer();
     rendererDireita.setHorizontalAlignment(SwingConstants.RIGHT);
     DefaultTableCellRenderer rendererEsquerda = new DefaultTableCellRenderer();
     rendererEsquerda.setHorizontalAlignment(SwingConstants.LEFT);

     JTableHeader header = TBtabelaconta.getTableHeader();
     header.setPreferredSize(new Dimension(0, 35));
     TableColumnModel modeloDaColuna = TBtabelaconta.getColumnModel();
     
    // Aqui se define se o texto vai ficar no meio ou nos cantos da coluna.
     
     modeloDaColuna.getColumn(0).setCellRenderer(rendererCentro); 
     modeloDaColuna.getColumn(1).setCellRenderer(rendererCentro); 

   // Aqui se define o tamanho das colunas.
     
     modeloDaColuna.getColumn(0).setMaxWidth(500);
     modeloDaColuna.getColumn(1).setMaxWidth(500);

 }
         
          private void novaConta(){ // Metodo para quando clicar no botão novo, habilitar e limpar os campos

      TFdescricaoconta.setText("");
      JCBtipoconta.setSelectedIndex(-1);
      JRBativoconta.setSelected(false);
      JRBinativoconta.setSelected(false);
      BTalterarcadastro.setEnabled(false);
      habilitarCampos();
      
     }
    
     private void limparCampos(){

      TFdescricaoconta.setText("");
      JCBtipoconta.setSelectedIndex(-1);
      JRBativoconta.setSelected(false);
      JRBinativoconta.setSelected(false);      

    }
     
     private boolean verificarCampos(){

        if(!TFdescricaoconta.getText().trim().equals("")){
            return true;
        }
        JOptionPane.showMessageDialog(this,"INFORME O NOME DA MODALIDADE !","CDS ACADEMIA",JOptionPane.WARNING_MESSAGE);
        return false;

    }
     
     private void cadastraConta(){ 

         if(verificarCampos() ){ 

            ContaControl gc = new ContaControl();
            ContaBean gb = new ContaBean();

            gb.setConta(TFdescricaoconta.getText().trim()); 
            gb.setTipo(JCBtipoconta.getSelectedItem().toString());
            if(JRBativoconta.isSelected()){ 
            gb.setStatus("ATIVO");
            }else if(JRBinativoconta.isSelected()){
            gb.setStatus("INATIVO");
            }else{
            JOptionPane.showMessageDialog(null,"INFORME O STATUS!","CDS ACADEMIA",JOptionPane.WARNING_MESSAGE);
            }

            gc.cadastraConta(gb);
            BTnovocadastro.setEnabled(true);
            limpaTabela();
            TFpesquisarconta.setText("");
            JOptionPane.showMessageDialog(null,"CONTA CADASTRADA COM SUCESSO","MENSAGEM DO PROGRAMA",JOptionPane.INFORMATION_MESSAGE);
            desabilitarCampos();

         }
        }
     
     private void alteraConta(){

         if(verificarCampos() ){ 

            ContaControl gc = new ContaControl();
            ContaBean gb = new ContaBean();

            gb.setConta(TFdescricaoconta.getText().trim());
            gb.setTipo(JCBtipoconta.getSelectedItem().toString());
            gb.setIdconta(contas.get(TBtabelaconta.getSelectedRow()).getIdconta()); 
            if(JRBativoconta.isSelected()){
            gb.setStatus("ATIVO");
            }else if(JRBinativoconta.isSelected()){
            gb.setStatus("INATIVO");
            }else{
            JOptionPane.showMessageDialog(null,"INFORME O STATUS!","CDS ACADEMIA",JOptionPane.WARNING_MESSAGE);
            }

            gc.alterarBanco(gb);
            BTnovocadastro.setEnabled(true);
            limpaTabela();
            TFpesquisarconta.setText("");
            JOptionPane.showMessageDialog(null,"CONTA ALTERADA COM SUCESSO","MENSAGEM DO PROGRAMA",JOptionPane.INFORMATION_MESSAGE);
            desabilitarCampos();

         }
        }
     
     private void excluirConta(){

        if(TBtabelaconta.getSelectedRow() != -1){
         int resposta = JOptionPane.showConfirmDialog(this,"Excluir Registro Selecionado ?","CONFIRMAÇÂO",JOptionPane.YES_NO_OPTION);
            if(resposta == JOptionPane.YES_OPTION){
                ContaControl gc = new ContaControl();
                gc.excluirBanco(contas.get(TBtabelaconta.getSelectedRow()).getIdconta());
                limpaTabela();
                TFdescricaoconta.setText("");
                TFpesquisarconta.setText("");
                JCBtipoconta.setSelectedIndex(-1);

            }
        }
    }
     
     private void habilitarCampos(){

     TFdescricaoconta.setEditable(true);
     JRBativoconta.setEnabled(true);
     JRBinativoconta.setEnabled(true);
     JCBtipoconta.setEditable(true);
     JCBtipoconta.setEnabled(true);
     JRBativoconta.setEnabled(true);
     JRBinativoconta.setEnabled(true);
   }

    private void desabilitarCampos(){

     TFdescricaoconta.setEditable(false);
     JRBativoconta.setEnabled(false);
     JRBinativoconta.setEnabled(false);
     JCBtipoconta.setEditable(false);
     JCBtipoconta.setEnabled(false);
     JRBativoconta.setEnabled(false);
     JRBinativoconta.setEnabled(false);

  }
     
     
     


    /**
     * Creates new form TelaCadastroAluno
     */
    public TelaCadastroConta() {
        initComponents();
        defineRenderers();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jTextField1 = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jToggleButton1 = new javax.swing.JToggleButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        TFpesquisarconta = new javax.swing.JTextField();
        BTpesquisarconta = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        TFdescricaoconta = new javax.swing.JTextField();
        jToolBar3 = new javax.swing.JToolBar();
        jPanel7 = new javax.swing.JPanel();
        JRBativoconta = new javax.swing.JRadioButton();
        JRBinativoconta = new javax.swing.JRadioButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        JCBtipoconta = new javax.swing.JComboBox();
        jToolBar1 = new javax.swing.JToolBar();
        BTnovocadastro = new javax.swing.JButton();
        BTalterarcadastro = new javax.swing.JButton();
        BTsalvarcadastro = new javax.swing.JButton();
        BTexcluircadastro = new javax.swing.JButton();
        BTexcluircadastro2 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        TBtabelaconta = new javax.swing.JTable();

        jTextField1.setText("jTextField1");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Foto", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 127, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 140, Short.MAX_VALUE)
        );

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jToggleButton1.setText("jToggleButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("CADASTRO DE CONTAS");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        jLabel1.setFont(new java.awt.Font("Yu Gothic", 1, 14)); // NOI18N
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Dollar.png"))); // NOI18N
        jLabel1.setText("CADASTRO DE CONTAS");

        TFpesquisarconta.setToolTipText("Digite a Descrição da Conta");

        BTpesquisarconta.setFont(new java.awt.Font("Yu Gothic", 0, 12)); // NOI18N
        BTpesquisarconta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Find.png"))); // NOI18N
        BTpesquisarconta.setText("Pesquisar");
        BTpesquisarconta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTpesquisarcontaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(TFpesquisarconta, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BTpesquisarconta)
                .addGap(18, 18, 18))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TFpesquisarconta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BTpesquisarconta, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel13.setFont(new java.awt.Font("Yu Gothic", 0, 12)); // NOI18N

        jTabbedPane1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        TFdescricaoconta.setEditable(false);
        TFdescricaoconta.setToolTipText("Descrição da Conta");

        jToolBar3.setBackground(new java.awt.Color(255, 255, 255));
        jToolBar3.setFloatable(false);
        jToolBar3.setRollover(true);

        jPanel7.setBackground(new java.awt.Color(255, 255, 255));
        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "STATUS", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Yu Gothic", 1, 12))); // NOI18N

        JRBativoconta.setBackground(new java.awt.Color(255, 255, 255));
        JRBativoconta.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        JRBativoconta.setText("ATIVO");
        JRBativoconta.setToolTipText("Conta Ativa");
        JRBativoconta.setEnabled(false);
        JRBativoconta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRBativocontaActionPerformed(evt);
            }
        });

        JRBinativoconta.setBackground(new java.awt.Color(255, 255, 255));
        JRBinativoconta.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        JRBinativoconta.setText("INATIVO");
        JRBinativoconta.setToolTipText("Conta Inativa");
        JRBinativoconta.setEnabled(false);
        JRBinativoconta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JRBinativocontaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JRBativoconta)
                    .addComponent(JRBinativoconta))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(JRBativoconta)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JRBinativoconta)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jLabel7.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        jLabel7.setText("DESCRIÇÃO:");

        jLabel8.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        jLabel8.setText("TIPO:");

        JCBtipoconta.setFont(new java.awt.Font("Yu Gothic", 1, 12)); // NOI18N
        JCBtipoconta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "DESPESA", "RECEITA" }));
        JCBtipoconta.setToolTipText("Tipo da Conta");
        JCBtipoconta.setEnabled(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(58, 58, 58)
                        .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel8)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(TFdescricaoconta, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                            .addComponent(JCBtipoconta, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(282, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(TFdescricaoconta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(JCBtipoconta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(0, 7, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("CONTAS", jPanel3);

        jToolBar1.setBorder(null);
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        BTnovocadastro.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTnovocadastro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Add.png"))); // NOI18N
        BTnovocadastro.setText("Novo");
        BTnovocadastro.setFocusable(false);
        BTnovocadastro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTnovocadastro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTnovocadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTnovocadastroActionPerformed(evt);
            }
        });
        jToolBar1.add(BTnovocadastro);

        BTalterarcadastro.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTalterarcadastro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Modify.png"))); // NOI18N
        BTalterarcadastro.setText("Alterar");
        BTalterarcadastro.setFocusable(false);
        BTalterarcadastro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTalterarcadastro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTalterarcadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTalterarcadastroActionPerformed(evt);
            }
        });
        jToolBar1.add(BTalterarcadastro);

        BTsalvarcadastro.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTsalvarcadastro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Apply.png"))); // NOI18N
        BTsalvarcadastro.setText("Salvar");
        BTsalvarcadastro.setFocusable(false);
        BTsalvarcadastro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTsalvarcadastro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTsalvarcadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTsalvarcadastroActionPerformed(evt);
            }
        });
        jToolBar1.add(BTsalvarcadastro);

        BTexcluircadastro.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTexcluircadastro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/Erase.png"))); // NOI18N
        BTexcluircadastro.setText("Excluir");
        BTexcluircadastro.setFocusable(false);
        BTexcluircadastro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTexcluircadastro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTexcluircadastro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTexcluircadastroActionPerformed(evt);
            }
        });
        jToolBar1.add(BTexcluircadastro);

        BTexcluircadastro2.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
        BTexcluircadastro2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/No.png"))); // NOI18N
        BTexcluircadastro2.setText("Cancelar");
        BTexcluircadastro2.setFocusable(false);
        BTexcluircadastro2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BTexcluircadastro2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BTexcluircadastro2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BTexcluircadastro2ActionPerformed(evt);
            }
        });
        jToolBar1.add(BTexcluircadastro2);

        TBtabelaconta.setFont(new java.awt.Font("Yu Gothic", 0, 12)); // NOI18N
        TBtabelaconta.setModel(tmContas);
        TBtabelaconta.setToolTipText("Contas");
        TBtabelaconta.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmContas = TBtabelaconta.getSelectionModel();
        lsmContas.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(!e.getValueIsAdjusting()){
                    tbContasLinhaSelecionada(TBtabelaconta);
                }
            }
        });
        jScrollPane2.setViewportView(TBtabelaconta);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 740, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 29, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel13)
                        .addGap(152, 152, 152))))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 740, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(236, 236, 236)
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(204, 204, 204)
                .addComponent(jLabel13)
                .addContainerGap())
        );

        setSize(new java.awt.Dimension(795, 477));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void BTnovocadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTnovocadastroActionPerformed
    tipoCadastro = "novo"; 
    novaConta();
    BTsalvarcadastro.setEnabled(true);
    limpaTabela();
    JRBativoconta.setSelected(true);  
    BTnovocadastro.setEnabled(false);
    BTexcluircadastro.setEnabled(false);
    }//GEN-LAST:event_BTnovocadastroActionPerformed

    private void BTpesquisarcontaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTpesquisarcontaActionPerformed
        listarContas();
        limparCampos();
        novaConta();
        desabilitarCampos();
        BTnovocadastro.setEnabled(true);
        BTalterarcadastro.setEnabled(true); 
    }//GEN-LAST:event_BTpesquisarcontaActionPerformed

    private void BTsalvarcadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTsalvarcadastroActionPerformed
if(tipoCadastro.equals("novo")){
        cadastraConta();
    }else if (tipoCadastro.equals("alteracao")){
        alteraConta();
    }
        limparCampos();    
        BTnovocadastro.setEnabled(true);
        BTexcluircadastro.setEnabled(true);
    }//GEN-LAST:event_BTsalvarcadastroActionPerformed

    private void BTalterarcadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTalterarcadastroActionPerformed
 tipoCadastro = "alteracao";
 BTsalvarcadastro.setEnabled(true);
 habilitarCampos();         // TODO add your handling code here:
    }//GEN-LAST:event_BTalterarcadastroActionPerformed

    private void BTexcluircadastroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTexcluircadastroActionPerformed
excluirConta();        // TODO add your handling code here:
    }//GEN-LAST:event_BTexcluircadastroActionPerformed

    private void BTexcluircadastro2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BTexcluircadastro2ActionPerformed
    novaConta();
    desabilitarCampos();
    BTalterarcadastro.setEnabled(true);
    BTnovocadastro.setEnabled(true);
    JRBativoconta.setSelected(false);
    limpaTabela();
    // TODO add your handling code here:
    }//GEN-LAST:event_BTexcluircadastro2ActionPerformed

    private void JRBativocontaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRBativocontaActionPerformed
if(JRBativoconta.isSelected()){
   JRBinativoconta.setSelected(false);    
    }           // TODO add your handling code here:
    }//GEN-LAST:event_JRBativocontaActionPerformed

    private void JRBinativocontaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JRBinativocontaActionPerformed
if(JRBinativoconta.isSelected()){
   JRBativoconta.setSelected(false);
    }        // TODO add your handling code here:
    }//GEN-LAST:event_JRBinativocontaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroConta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroConta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroConta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroConta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaCadastroConta().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BTalterarcadastro;
    private javax.swing.JButton BTexcluircadastro;
    private javax.swing.JButton BTexcluircadastro2;
    private javax.swing.JButton BTnovocadastro;
    private javax.swing.JButton BTpesquisarconta;
    private javax.swing.JButton BTsalvarcadastro;
    private javax.swing.JComboBox JCBtipoconta;
    private javax.swing.JRadioButton JRBativoconta;
    private javax.swing.JRadioButton JRBinativoconta;
    private javax.swing.JTable TBtabelaconta;
    private javax.swing.JTextField TFdescricaoconta;
    private javax.swing.JTextField TFpesquisarconta;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar3;
    // End of variables declaration//GEN-END:variables
}
